package cn.hughie.thread;

import javax.crypto.spec.IvParameterSpec;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;

/**
 * @Author yuh
 * @Date Created in 上午8:10 2018/5/24
 * @Description Callable测试
 */
public class Thread5 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        List<Future<Integer>> futures = new ArrayList<>(5);
        for (int i = 0; i < 5; i++) {
            futures.add(executorService.submit(new Calc()));

        }
        for (Future<Integer> future : futures) {
            System.out.println(future.get());
        }
        executorService.shutdown();
    }
}

class Calc implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        Random random = new Random();
        Thread.sleep(random.nextInt(50000));
        return random.nextInt();
    }
}
